package com.sinodata.bsm.cicp.util;

import com.sinodata.bsm.cicp.cache.CacheFactory;
import com.sinodata.bsm.cicp.cache.ProtocolParameterCache;
import com.sinodata.bsm.common.constants.ProtocolConstants;
import com.sinodata.bsm.common.vo.ProtocolParameter;

/**
 * <p>
 * Description: 采集协议获取工具类
 * </p>
 *
 * @author liulibo
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-5-15 PM 4:49:22     liulibo        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class ProtocolParameterUtil {

    /**
     * 根据Linux\Unix主机的IP获取采集协议配置对象
     * 
     * @param ip
     * @return
     */
    public static ProtocolParameter getHostValue(String ip) {
        ProtocolParameterCache cache = (ProtocolParameterCache) CacheFactory.getInstance().getCache(ProtocolParameterCache.class);
        return cache.get(ProtocolConstants.TYPE_HOST, ip);
    }

    /**
     * 根据Windows主机的IP获取采集协议配置对象
     * 
     * @param ip
     * @return
     */
    public static ProtocolParameter getWmiValue(String ip) {
        ProtocolParameterCache cache = (ProtocolParameterCache) CacheFactory.getInstance().getCache(ProtocolParameterCache.class);
        return cache.get(ProtocolConstants.TYPE_WMI, ip);
    }

    /**
     * 根据数据库的IP、类型、实例名获取采集协议配置对象
     * 
     * @param ip
     * @param dbType
     * @param dbName
     * @return
     */
    public static ProtocolParameter getJdbcValue(String ip, String dbType, String dbName) {
        ProtocolParameterCache cache = (ProtocolParameterCache) CacheFactory.getInstance().getCache(ProtocolParameterCache.class);
        return cache.get(ProtocolConstants.TYPE_JDBC, ip, dbType, dbName);
    }

    /**
     * 根据JMX的IP、中间件类型、端口获取采集协议配置对象
     * 
     * @param ip
     * @param dbType
     * @param port
     * @return
     */
    public static ProtocolParameter getJmxValue(String ip, Integer port) {
        ProtocolParameterCache cache = (ProtocolParameterCache) CacheFactory.getInstance().getCache(ProtocolParameterCache.class);
        return cache.get(ProtocolConstants.TYPE_JMX, ip, port);
    }

    /**
     * 根据HTTP的IP、URL地址获取采集协议配置对象
     * 
     * @param ip
     * @param url
     * @return
     */
    public static ProtocolParameter getHttpValue(String url) {
        ProtocolParameterCache cache = (ProtocolParameterCache) CacheFactory.getInstance().getCache(ProtocolParameterCache.class);
        return cache.getHttpProtocolParameter(ProtocolConstants.TYPE_HTTP, url);
    }

    /**
     * 根据SNMP的IP获取采集协议配置对象
     * 
     * @param ip
     * @return
     */
    public static ProtocolParameter getSnmpValue(String ip) {
        ProtocolParameterCache cache = (ProtocolParameterCache) CacheFactory.getInstance().getCache(ProtocolParameterCache.class);
        return cache.get(ProtocolConstants.TYPE_SNMP, ip);
    }
}
